package PenTest.huawei.mianshiti;

import java.util.*;

public class Main {

    private static int res=0;

    public static void main(String[] args) {
        System.out.println(isPalindrome("aabb"));  // True
        System.out.println(isPalindrome("abc"));   // False
        System.out.println(isPalindrome("aab"));   // True
        System.out.println(isPalindrome("a"));     // True
        System.out.println(isPalindrome("aaabbb")); // False
    }

    private static boolean isPalindrome(String s) {
        char[] chars = s.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        for (char c : chars) {
            map.put(c,map.getOrDefault(c,0)+1);
        }
        int odd=0;
        for (char c : chars) {
            if(map.get(c)%2!=0){
                odd++;
            }
        }

        if(s.length()%2==0){
            return odd==0;
        }else {
            return odd<=1;
        }
    }

}
